You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[STALE: REBASE FROM NEW FORK] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004) - #23
Anthropic answers 400 messages.N.content.0: Invalid `signature` in `thinking` block when a replayed thinking block was minted under a different model or account than the one now serving the call (AGE-2004, Мира aebc14d8: House Claude, rotated account/model mid-conversation). Today that 400 goes straight back to the agent and the turn is dead.
Now the Anthropic adapter recovers once, inside the same call: on exactly that 400 it rebuilds the request with every thinking / redacted_thinking block removed from the history and resends. Anthropic allows omitting history thinking. If the last assistant turn held a tool_use (open tool loop), the dropped block would be required with thinking on, so that one resend goes with thinking disabled (or absent on models without explicit disable).
Both request lanes are covered: the translated lane (messagesToAnthropicFormat) and the canonical raw source-replay lane (body cloned from the Claude client).
One resend per request (thinkingReplayGuard); a second rejection is returned to the caller unchanged. Unrelated 400s are never resent. Match is the exact Anthropic message, a display-safe bounded body, adapter anthropic, status 400 only.
New recovery kind anthropic-thinking-replay (cause ciphertext-refusal, status 400) in the telemetry roster, failure model, attribution table, Logs page label and all 10 catalogs.
No client protocol change, no change to inbound guards, no envelope change.
Design note: why not carry the model in the envelope
The first plan was to stamp the minting model into the ocxr1 envelope and drop mismatches. The raw source-replay lane and raw client signatures (src/claude/outbound.ts, src/claude/inbound.ts:281-287) carry the signature raw, so the minting model cannot be attached there. A stateless retry on the real rejection covers both lanes and needs no stored state.
Trade-off: while the client keeps sending the stale blocks, each turn costs one extra failed 400 before the resend (no extra billed tokens; the 400 is rejected before generation).
OPEN question
Does Anthropic reject the same model's signature across different accounts, or only across models? This fix recovers either way, so it does not need an answer; the recovery-kind counter in the request log will show how often it fires.
Agent's-eye text
No text the agent sees changes on success: the agent gets a normal answer and the turn continues. On a second rejection the agent receives the unchanged Anthropic 400 body (same as before this change).
Tests
tests/responses/responses-anthropic-thinking-replay.test.ts: closed turn resend drops blocks and keeps thinking; open tool loop resend turns thinking off and keeps the tool_use; unrelated 400 is not resent; second rejection returned after one resend. Roster, attribution, failure-stage and Logs label oracles pass (105 tests, 7 files).
github-actionsBot
changed the title
anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004)
[WRONG BRANCH] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004)
Nov 13, 2026
wrong target branch (release/2.65.0-vadymhimself.15); retarget to dev. UI screenshot required.
What to do
Retarget this PR to dev — all contributions go to dev.
Add a screenshot of the UI change to the PR description.
Its title has been prefixed with [WRONG BRANCH].
This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again.
vadymhimself
changed the title
[WRONG BRANCH] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004)
[STALE: REBASE FROM NEW FORK] anthropic: retry once without history thinking blocks on invalid thinking signature (AGE-2004)
Nov 18, 2026
This PR is based on the superseded 2.65 gateway line. Rebuild the change from port/ar-on-upstream-2026-11-18 (upstream-derived 2.100 AR overlay, PR #46): #46 . Do not rebase onto or merge the old release line. Preserve the new gateway quota/cache gate and re-run the affected regressions. The candidate is not deployed; do not publish or replace a running gateway without explicit approval.
main is now the stable upstream-derived AgentRadar gateway line:2.100.0-vadymhimself.2, merged via #47 (merge commit ad594a0778). Its tree is identical to the tested candidate 6a14467972, and it shares history with upstream lidge-jun/opencodex dev at 6bae884cbc.
Trial evidence: before the merge the build ran 30.5 h on the laptop gateway and 24 h on the personal Mac Mini gateway, both with OPENCODEX_AGENTRADAR=1. Neither restarted and neither left unresolved spend. The Mini served 11,138 requests with 2 5xx; the old build had 303 502s over the prior day. The remaining non-2xx were exhausted provider quota, not gateway faults. The fork's GitHub Actions has not run since Nov 18, so there is no CI result. Run checks locally.
For new work:
Branch from main. Do not target release/2.65.0-vadymhimself.*.
Check FORK-DELTA.md first; many old-line fixes are already carried or upstream-equivalent.
If a behavior is still missing, re-cut it as a small, single-concern change on main.
Before opening a PR, use pinned Bun 1.4.4 with an isolated HOME/OPENCODEX_HOME, synthetic credentials and loopback providers (never live accounts):
bun run test:gateway-quota (29-file AR gateway gate)
affected suites: bun scripts/test.ts --changed=main
bun run typecheck, bun run structure:check, bun run privacy:scan, git diff --check
Hosted-only behavior needs OPENCODEX_AGENTRADAR=1 set inside the test; without it the branch behaves like upstream. Register new test files in scripts/test-layout/layout-agentradar.json.
For this PR: not carried (no entry in FORK-DELTA.md). If invalid-signature retries are still needed, re-cut on main with a hosted-fidelity style test (tests/claude-integration/agentradar-hosted-fidelity.test.ts), and keep the exact canonical relay intact.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Anthropic answers 400
messages.N.content.0: Invalid `signature` in `thinking` blockwhen a replayed thinking block was minted under a different model or account than the one now serving the call (AGE-2004, Мира aebc14d8: House Claude, rotated account/model mid-conversation). Today that 400 goes straight back to the agent and the turn is dead.Now the Anthropic adapter recovers once, inside the same call: on exactly that 400 it rebuilds the request with every
thinking/redacted_thinkingblock removed from the history and resends. Anthropic allows omitting history thinking. If the last assistant turn held atool_use(open tool loop), the dropped block would be required with thinking on, so that one resend goes withthinkingdisabled (or absent on models without explicit disable).messagesToAnthropicFormat) and the canonical raw source-replay lane (body cloned from the Claude client).thinkingReplayGuard); a second rejection is returned to the caller unchanged. Unrelated 400s are never resent. Match is the exact Anthropic message, a display-safe bounded body, adapteranthropic, status 400 only.anthropic-thinking-replay(causeciphertext-refusal, status 400) in the telemetry roster, failure model, attribution table, Logs page label and all 10 catalogs.Design note: why not carry the model in the envelope
The first plan was to stamp the minting model into the
ocxr1envelope and drop mismatches. The raw source-replay lane and raw client signatures (src/claude/outbound.ts,src/claude/inbound.ts:281-287) carry the signature raw, so the minting model cannot be attached there. A stateless retry on the real rejection covers both lanes and needs no stored state.Trade-off: while the client keeps sending the stale blocks, each turn costs one extra failed 400 before the resend (no extra billed tokens; the 400 is rejected before generation).
OPEN question
Does Anthropic reject the same model's signature across different accounts, or only across models? This fix recovers either way, so it does not need an answer; the recovery-kind counter in the request log will show how often it fires.
Agent's-eye text
No text the agent sees changes on success: the agent gets a normal answer and the turn continues. On a second rejection the agent receives the unchanged Anthropic 400 body (same as before this change).
Tests
tests/responses/responses-anthropic-thinking-replay.test.ts: closed turn resend drops blocks and keeps thinking; open tool loop resend turns thinking off and keeps the tool_use; unrelated 400 is not resent; second rejection returned after one resend. Roster, attribution, failure-stage and Logs label oracles pass (105 tests, 7 files).Eval added/updated: N/A deterministic (unit/integration test: tests/responses/responses-anthropic-thinking-replay.test.ts)
🤖 Generated with Claude Code